#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<iostream>
using namespace std;
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int>arr(n);
    for (int i = 0; i < n; i++)cin >> arr[i];
    int ans = 0;
    vector<int>cnt(n + 1, 0);
    for (int i = 0; i < m; i++)
        cnt[arr[i]]++;
    while (cnt[ans] > 0)ans++;
    for (int i = m; i < n; i++) {
        cnt[arr[i - m]]--;
        cnt[arr[i]]++;
        if (cnt[arr[i - m]] == 0 && arr[i - m] < ans)
            ans = arr[i - m];
    }
    cout << ans << endl;
}
int main()
{
    solve();
    return 0;
}